package de.reichelt.fxrequi;

import de.reichelt.fx.FxForm;
import de.reichelt.fx.FxOption;
import de.reichelt.fxrequi.data.DataStore;
import de.reichelt.fxrequi.data.Project;
import de.reichelt.fxrequi.data.Testpack;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

public class TestplanController extends BaseController {

  @FXML private HBox panNavigation;
  @FXML private Button btnProjekt;
  @FXML private Button btnAnforderung;
  @FXML private Button btnNew;
  @FXML private Button btnEdit;
  @FXML private Button btnGenerate;
  
  @FXML private HBox btnNavigation2;
  @FXML private ComboBox<Testpack> cmbTestpack;
  @FXML private Button btnNewTestpack;
  
  @FXML private AnchorPane panTable;
  @FXML private TableView<?> tableTestcases;
  @FXML private TableColumn<?, ?> colCounter;
  @FXML private TableColumn<?, ?> colTitle;
  @FXML private TableColumn<?, ?> colDescr;
  @FXML private TableColumn<?, ?> colNr;
  
  @FXML private AnchorPane panTestcase;
  @FXML private TextField txtNr;
  @FXML private ComboBox<FxOption> cmbPriority;
  @FXML private FlowPane flowKeywords;
  @FXML private TextArea txtDescr;
  @FXML private TextArea txtConfig;
  @FXML private TextArea txtPre;
  @FXML private TextArea txtPost;
  @FXML private TextArea txtSkript;
  @FXML private Button btnCancel;
  @FXML private Button btnSave;
  
  @FXML private VBox panTeststeps;
  @FXML private AnchorPane panTeststep;
  
  
  private Logger log;
  private FxForm form;
  private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

  public TestplanController() {
    super();
    log = Logger.getLogger(this.getClass().getName());
    
  }
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
    try {
    DataStore ds = DataStore.getInstance();
    cmbTestpack.setItems(ds.getTestpacksForProject(FXrequi.APP.getSelectedProject().getName()));
    
    
    
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Fehler beim Erzeugen der Testplanansicht!", ex);
      FXrequi.APP.showError("Fehler beim Erzeugen der Testplanansicht!");
    }
    
    btnProjekt.setOnAction(this::showProjectAction);
    
  }
  
  private void showProjectAction(ActionEvent event) {
    log.fine("aufgerufen");
    try {
      FXrequi.APP.setTopPane(null);
      FXMLLoader ldr = new FXMLLoader(this.getClass().getResource("ProjectView.fxml"));
      AnchorPane pane = (AnchorPane)ldr.load();
      FXrequi.APP.setMainPane(pane);
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Fehler beim Erzeugen der Projektansicht!", ex);
      FXrequi.APP.showError("Fehler beim Erzeugen der Projektansicht!");
    }
  }
  
}
